package com.fhz.kotlinstest.pagingSource

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.fhz.kotlinstest.R
import com.fhz.kotlinstest.paging.UserAdapter.InnerViewHolder

class Pag3Adapter : PagingDataAdapter<String, Pag3Adapter.Pag3ViewHolder>(POST_COMPARATOR) {

    class Pag3ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var mIdTv: TextView = itemView.findViewById(R.id.item_tv)
    }
    companion object {
        private val POST_COMPARATOR = object : DiffUtil.ItemCallback<String>() {
            override fun areItemsTheSame(oldItem: String, newItem: String): Boolean = true

            override fun areContentsTheSame(oldItem: String, newItem: String): Boolean {
                return true
            }
        }
    }

    override fun onBindViewHolder(holder: Pag3ViewHolder, position: Int) {
        holder.mIdTv.text = getItem(position)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Pag3ViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.pag3_item_layout,parent,false)
        return Pag3ViewHolder(view)
    }
}